#include <unistd.h>
#include "selfpool.h"
void demo_task(void *arg)
{
    int *num = (int *)arg;
    printf("Processing task %d,selfpool tid %ld\n", *num ,pthread_self());
    sleep(1);
    printf("finish task %d,selfpool tid %ld\n",*num ,pthread_self());
    free(num);
}

int main()
{
    // 初始化线程池（3-10个线程）
    threadpool_t *pool = threadpool_init(10, 20);

    // 添加20个任务
    for (int i = 0; i < 50; i++)
    {
        int *arg = malloc(sizeof(int));
        *arg = i;
        threadpool_add_task(pool, demo_task, arg, NULL, i % 3);
    }

    // 监控状态
    threadpool_status_t status;
    do
    {
        threadpool_get_status(pool, &status);
        printf("Threads: %d/%d (Active: %d), Tasks: %d\n",
               status.thread_count, pool->max_thread_count,
               pool->active_thread_count, status.task_count);
        sleep(1);
    } while (status.task_count > 0);

    // 调整线程池参数
    threadpool_adjust(pool, 2, 8);

    // 销毁线程池
    threadpool_destroy(pool);
    return 0;
}